#pragma GCC optimize(2, "Ofast", "inline")
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <algorithm>
#define endl '\n'
#define int long long
#define pii pair<int, int>
using namespace std;
const int MOD = 998244353;
const int MXN = 2e5 + 5;


int n;
int a[MXN];
int f[222222];
int tnt = 0;
signed main()
{
    // 输入输出优化
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1;i <= n;i++)
    {
        cin >> a[i];
        f[a[i]]++;
    }
    for (int i = 1;i <= n;i++)
    {
        if (f[i] >= 2) tnt += f[i] * (f[i] - 1) / 2 * (n - f[i]); // 选两个i和其他的数字组合 
    }
    cout << tnt << endl;
    return 0;
}